package com.jeeplus.servicecenter.service.dto;


import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.jeeplus.core.excel.converter.ExcelOfficeDTOConverter;
import com.jeeplus.core.excel.converter.ExcelPostListDTOConverter;
import com.jeeplus.core.excel.converter.ExcelRoleListDTOConverter;
import com.jeeplus.core.service.dto.BaseDTO;
import com.jeeplus.sys.service.dto.OfficeDTO;
import com.jeeplus.sys.service.dto.PostDTO;
import com.jeeplus.sys.service.dto.RoleDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.stream.Collectors;

@Data
@EqualsAndHashCode(callSuper = false)
public class AgreeAssociationApplyDTO extends BaseDTO {

    private String id;

    /**
     * 登录名
     */
    @ExcelProperty("登录名")
    private String loginName;


    /**
     * 学校id
     */
    @ExcelProperty("学校id")
    private String companyId;

    /**
     * 工会id
     */
    @ExcelProperty("工会id")
    private String officeId;

    /**
     * 职位id
     */
    @ExcelProperty("职位id")
    private String roleId;

    /**
     * 岗位id
     */
    @ExcelProperty("岗位id")
    private String postId;

    /**
     * 归属公司
     */
    @ApiModelProperty(hidden = true)
    @ExcelProperty(value = "公司", converter = ExcelOfficeDTOConverter.class)
    private OfficeDTO companyDTO;

    /**
     * 归属部门
     */
    @ApiModelProperty(hidden = true)
    @ExcelProperty(value = "部门", converter = ExcelOfficeDTOConverter.class)
    private OfficeDTO officeDTO;

    /**
     * 拥有角色列表
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    @ExcelProperty(value = "角色", converter = ExcelRoleListDTOConverter.class)
    private List<RoleDTO> roleDTOList = Lists.newArrayList ( );

    /**
     * 拥有岗位列表
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    @ExcelProperty(value = "岗位", converter = ExcelPostListDTOConverter.class)
    private List <PostDTO> postDTOList = Lists.newArrayList ( );

    public AgreeAssociationApplyDTO(){ super();}
    public AgreeAssociationApplyDTO(String id) {
        super ( id );
    }

    /**
     * 获取包含的角色id列表
     *
     * @return
     */
    public List <String> getRoleIdList() {
        if ( roleDTOList == null ) {
            return Lists.newArrayList ( );
        }
        List <String> roleIdList = roleDTOList.stream ( ).map ( roleDTO -> roleDTO.getId ( ) ).collect ( Collectors.toList ( ) );
        return roleIdList;
    }

    /**
     * 设置角色
     *
     * @param roleIdList
     */
    public void setRoleIdList(List <String> roleIdList) {
        for (String roleId : roleIdList) {
            RoleDTO roleDTO = new RoleDTO ( roleId );
            roleDTOList.add ( roleDTO );
        }
    }

    /**
     * 获取包含的岗位id列表
     *
     * @return
     */
    public List <String> getPostIdList() {
        if ( postDTOList == null ) {
            return Lists.newArrayList ( );
        }
        List <String> postIdList = postDTOList.stream ( ).map ( postDTO -> postDTO.getId ( ) ).collect ( Collectors.toList ( ) );
        return postIdList;
    }

    /**
     * 设置岗位
     *
     * @param postIdList
     */
    public void setPostIdList(List <String> postIdList) {
        for (String postId : postIdList) {
            PostDTO postDTO = new PostDTO ( postId );
            postDTOList.add ( postDTO );
        }
    }
}
